import { defineStore } from 'pinia'
import { reqCategory1, reqCategory2, reqCategory3 } from '@/api/category'
import type { Category } from '@/api/types'

export const useCategoryStore = defineStore('category', {
  state: (): Category => {
    return {
      category1Id: '',
      category2Id: '',
      category3Id: '',
      category1List: [],
      category2List: [],
      category3List: []
    }
  },
  actions: {
    async getCategory1() {
      const res = await reqCategory1()
      if (res.code === 200) {
        this.category1List = res.data
      }
    },
    async getCategory2(id: string) {
      const res = await reqCategory2(id)
      if (res.code === 200) {
        this.category2List = res.data
      }
    },
    async getCategory3(id: string) {
      const res = await reqCategory3(id)
      if (res.code === 200) {
        this.category3List = res.data
      }
    }
  }
})
